package com.zbkj.crmeb.store.service.impl;

import java.math.BigDecimal;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.common.PageParamRequest;
import com.github.pagehelper.PageHelper;
import com.zbkj.crmeb.chant.service.IChannelMerchantService;
import com.zbkj.crmeb.enums.OrderTradeTypeEnum;
import com.zbkj.crmeb.store.dao.StoreAccountInfoDao;
import com.zbkj.crmeb.store.model.StoreAccountInfo;
import com.zbkj.crmeb.store.request.StoreAccountInfoRequest;
import com.zbkj.crmeb.store.service.StoreAccountInfoService;
import com.zbkj.crmeb.system.service.SystemAdminService;

import lombok.extern.slf4j.Slf4j;

/**
* @author cyz
* @description StoreAccountInfoServiceImpl 接口实现
* @date 2021-04-20
*/
@Slf4j
@Service
public class StoreAccountInfoServiceImpl extends ServiceImpl<StoreAccountInfoDao, StoreAccountInfo> implements StoreAccountInfoService {
    @Resource
    private StoreAccountInfoDao dao;
    @Resource
    private SystemAdminService systemAdminService;
    @Resource
    private IChannelMerchantService channelMerchantService;

    @Override
    public BigDecimal selectAlreadyRefundPrice(StoreAccountInfoRequest request) {
        BigDecimal price = dao.selectAlreadyRefundPrice(request);
        if (null == price) {
            return new BigDecimal("0");
        }
        return price;
    }

    @Override
    public List<StoreAccountInfo> getList(StoreAccountInfoRequest request, PageParamRequest pageParamRequest) {
        PageHelper.startPage(pageParamRequest.getPage(), pageParamRequest.getLimit());
        LambdaQueryWrapper<StoreAccountInfo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StoreAccountInfo::getUid, request.getUid());
        queryWrapper.eq(StoreAccountInfo::getIsAccount, 1);
        queryWrapper.orderByDesc(StoreAccountInfo::getUpdateTime);
        List<StoreAccountInfo> infoList = dao.selectList(queryWrapper);
        infoList.stream().forEach(info -> {
            info.setTradeTypeName(OrderTradeTypeEnum.getTypeByCode(info.getTradeType()).getTypeName());
        });
        return infoList;
    }

}
